package com.xzw.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xzw.mapper.OperateLogMapper;
import com.xzw.pojo.LogQueryParam;
import com.xzw.pojo.OperateLog;
import com.xzw.pojo.PageResult;
import com.xzw.service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private OperateLogMapper operateLogMapper;

    /**
     * 分页查询 操作日志
     */
    @Override
    public PageResult<OperateLog> page(LogQueryParam logQueryParam) {
        // 1.设置分页参数
        PageHelper.startPage(logQueryParam.getPage(), logQueryParam.getPageSize());
        // 2.执行查询
        List<OperateLog> operateLogList = operateLogMapper.list(logQueryParam);
        // 3.解析查询结果，并封装
        Page<OperateLog> p = (Page<OperateLog>) operateLogList;
        return new PageResult<OperateLog>(p.getTotal(), p.getResult());
    }
}
